Skip to content

Comments

sqlite: support reading NULL as undefined in result sets#61472

Open
mattskel wants to merge 3 commits intonodejs:mainfrom
mattskel:sqlite-59457-read-null-as-undefined-support
Open

sqlite: support reading NULL as undefined in result sets#61472
mattskel wants to merge 3 commits intonodejs:mainfrom
mattskel:sqlite-59457-read-null-as-undefined-support

Conversation

@mattskel
Copy link

@mattskel mattskel commented Jan 22, 2026

Add a statement-level flag to control how SQL NULL values are materialised in results. Expose setReadNullAsUndefined() on StatementSync and apply it to row-reading paths (get, all, iterate, columnToValue) without affecting function arguments or write paths.

Fixes: #59457

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Jan 22, 2026
} \
} while (0)

#define SQLITE_VALUE_TO_JS_READ(from, isolate, use_big_int_args, \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This much duplication is not acceptable.

break; \
} \
case SQLITE_NULL: { \
(result) = (read_null_as_undef) ? Undefined((isolate)) : Null((isolate)); \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main difference between SQLITE_VALUE_TO_JS_READ and SQLITE_VALUE_TO_JS is just the way of handling null values? Can we simplify the code?

@geeksilva97
Copy link
Contributor

Thanks for this PR. I'm still struggling to see a reason for it.

@mattskel mattskel force-pushed the sqlite-59457-read-null-as-undefined-support branch from de7bf9f to 66ce7e4 Compare January 25, 2026 07:13
@mattskel mattskel marked this pull request as ready for review January 25, 2026 07:14
@mattskel mattskel requested review from himself65 and louwers January 25, 2026 07:14
@mike-git374
Copy link

mike-git374 commented Feb 14, 2026

There is similar PR here #59462, I have not compared them.

Any PR for this issue needs to add to database.prepare(sql[, options]) as the statement.set* functions should be deprecated after db.prepare(sql, options) was added.

Also the option should be added to new DatabaseSync(path[, options]) in addition to db.prepare(sql, options)

Add a statement-level flag to control NULL conversion.
Expose setReadNullAsUndefined() on StatementSync.
Apply to row-reading paths.
Fixes: nodejs#59457
Refactor SQLITE_NULL case in SQLITE_VALUE_TO_JS.
Remove SQLITE_VALUE_TO_JS_READ macro.
Update sqlite docs.
Add testing for SetReadNullAsUndefined implementation.
Add support for the readNullAsUndefined option.
Added to database.prepare and DatabseSync.
Option can be set at db level.
Or overridden at statement level.

Refs: nodejs#61472 (comment)
Refs: nodejs#61311
@mattskel mattskel force-pushed the sqlite-59457-read-null-as-undefined-support branch from 66ce7e4 to 0bf1052 Compare February 21, 2026 14:06
@mattskel
Copy link
Author

@mike-git374 the changes you requested have been made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite: statement.setReadNullAsUndefined()

6 participants